<?php

require('init.php');
$title = 'History Contests';
require(LIBWWWDIR . '/header.php');

echo "<h1> Past Inner Contests</h1>\n\n";

// Get data. Starttime seems most logical sort criterion.
$res = query_contest($conn_db2, "0");

if( $res[0] == 0 ){
	echo "<p class=\"nodata\">No contests defined</p>\n\n";
}else{
	$int_end = array();
	$now = now();
	for( $i=1; $i<=$res[0]; $i++ ){
		if( difftime($now,$res[$i]['endtime']) > 0 ){
			$int_end[]=$res[$i];
		}
	}
	if( count($int_end) == 0 ){
		echo "No Internal Contests finish Yed";
	}else{
		echo "<table class=\"list sortable\">\n<thead>\n" .
	     	"<tr><th scope=\"col\">ICID</th><th scope=\"col\">ends</th>".
	    	 "<th scope=\"col\">unfreeze</th>" .
	    	 "<th scope=\"col\">name</th></tr>\n</thead>\n<tbody>\n";

		for( $i=0; $i<count($int_end); $i++ )
		{
			//$link = '<a href="contest_h.php?id=' . urlencode($row['cid']) . '">';
			$link = '<a href="problems_past.php?id=' . urlencode($int_end[$i]['cid']).'">';
			echo '<tr class="' .
			( $iseven ? 'roweven': 'rowodd' ) .
			(!$int_end[$i]['enabled']    ? ' disabled' :'') .
			($int_end[$i]['cid'] == $cid ? ' highlight':'') . '">' .
			"<td align=\"right\">" . $link .
			"c" . (int)$int_end[$i]['cid'] . "</a></td>\n" .
			"<td title=\"".htmlspecialchars($int_end[$i]['endtime']) . "\">" .
			$link . $int_end[$i]['endtime'].
			"<td title=\"".htmlspecialchars(@$int_end[$i]['unfreezetime']) . "\">" .
			$link . ( isset($int_end[$i]['unfreezetime']) ?
			  printtime($int_end[$i]['unfreezetime']) : '-' ) . "</a></td>\n" .
			"<td>" . $link . htmlspecialchars($int_end[$i]['contestname']) . "</a></td>\n";
			$iseven = ! $iseven;
			echo "</tr>\n";
		}
	}
}



require(LIBWWWDIR . '/footer.php');
